package com.pet.controller;

import com.pet.vo.SysResult;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/auth")
public class AuthController {
    private String token;
    private String userName;
    @PostMapping("/token")
    public void setAuth(String token,String msg){
        this.token = token;
        this.userName = msg;
        System.out.println("登录成功");
    }
    @GetMapping("/getAuth")
    public SysResult getAuth(){
        if(token != null){
            return SysResult.success();
        }
        return SysResult.fail();
    }
    @GetMapping("/getUserName")
    public SysResult getUserName(){
        if(userName != null){
            return SysResult.success(userName);
        }
        return SysResult.fail();
    }
    @PostMapping("/logout")
    public SysResult logout(){
        if(token != null){
            this.token = null;
            this.userName = null;
            return SysResult.success();
        }
        return SysResult.fail();
    }
}
